home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 352_01.zip / STRPPSQZ.CPP < prev    next >
C/C++ Source or Header  |  1993-04-10  |  1KB  |  50 lines

  1. // STRPPSQZ.CPP        contains String::squeeze 
  2. //        string squeeze. Any chars in s2 are removed from s1.
  3. //        METHOD: s pts to source string.
  4. //                p starts out at same place.
  5. //                for every char to keep, *s = *p and both are incremented.
  6. //                for every char to loose, p is incremented, s left alone.
  7. //    
  8. //
  9. #include <stdlib.h>
  10. #include <string.h> 
  11.  
  12. #include "dblib.h"
  13.  
  14.  
  15. String& String::squeeze (char *tok )
  16.     {
  17.     char *lag = s;        // ptr to remaining part of string
  18.     char *lead=lag;        // ptr to exploring part of string
  19.     if ( ! (lag ==NULL || tok==NULL ) )
  20.         {
  21.         int  ntok = strlen(tok);
  22.         char c;
  23.         
  24.         int  offset =0;
  25.             
  26.         for ( ; *lead; ++lead)
  27.             {
  28.             c = *lead;
  29.             if ( -1 == String::findchr ( tok, ntok, c )  )
  30.                 {
  31.                 /* character at p is not contained in s2, 
  32.                  *    so copy it to s and move offset on lagging  ptr up one.
  33.                  */
  34.                 lag[offset++] = c;
  35.                 }
  36.             }
  37.  
  38.         lag[offset] =0;
  39.         n = offset;    
  40.     
  41.         if ( offset ==0 )
  42.             {
  43.             // entire string was squeezed, 
  44.             destruct();
  45.             }
  46.         }    
  47.  
  48.     return  *this; /* strsqz() */
  49.     }
  50. /*-------------------- end of strsqz() ----------------------------- */